#include"ringqueue.hpp"
#include<ctime>

void* consumer(void* argc)
{
    ringqueue<int>* rq=static_cast<ringqueue<int>*>(argc);
    while(true)
    {
        int num = rq->pop();
        cout<<"时间:"<<(unsigned int) time(nullptr)<<" consumer tid:"<<pthread_self()<<"消费数据 num:"<<num<<endl;
    }
}

void* producter(void* argc)
{
    ringqueue<int>* rq=static_cast<ringqueue<int>*>(argc);
    while(true)
    {
        int num=rand()%12;
        rq->push(num);
        cout<<"时间:"<<(unsigned int) time(nullptr)<<" producter tid:"<<pthread_self()<<"生产数据num:"<<num<<endl;
        sleep(1);
    }
}


int main()
{
    srand((unsigned int)time(nullptr));
    pthread_t c1,c2,c3,p1,p2,p3;
    ringqueue<int> rq;
    pthread_create(&c1,nullptr,consumer,&rq);
    pthread_create(&c2,nullptr,consumer,&rq);
    pthread_create(&c3,nullptr,consumer,&rq);
    pthread_create(&p1,nullptr,producter,&rq);
    pthread_create(&p2,nullptr,producter,&rq);
    pthread_create(&p3,nullptr,producter,&rq);

    pthread_join(c1,nullptr);
    pthread_join(c2,nullptr);
    pthread_join(c3,nullptr);
    pthread_join(p1,nullptr);
    pthread_join(p2,nullptr);
    pthread_join(p3,nullptr);
    
    return 0;
}